package com.jsnkj.basic.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.jsnkj.basic.R
import com.jsnkj.basic.bean.MineItemBean


class MineAdapter(
    val context: Context,
    private val itemBeans: List<MineItemBean>,
    val itemClick: onItemClickListener
) :
    RecyclerView.Adapter<MineAdapter.HomeViewHolder>() {
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): HomeViewHolder {
        val view: View =
            LayoutInflater.from(parent.context).inflate(R.layout.rv_item_mine, parent, false)
        return HomeViewHolder(view)
    }

    override fun onBindViewHolder(holder: HomeViewHolder, position: Int) {
        val item = itemBeans[position]
        Glide.with(context).load(item.icon).into(holder.ivIcon)
        holder.tvTitle.setText(item.title)
//        holder.tvRemark.setText(item.getRemark())

        holder.conLayoutItem.setOnClickListener {
            if (null != itemClick) {
                itemClick.onItemCallBack(position)
            }
        }
    }

    override fun getItemCount(): Int {
        return itemBeans.size
    }

    class HomeViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
        var conLayoutItem: ConstraintLayout
        var ivIcon: ImageView
        var tvTitle: TextView

        init {
            conLayoutItem = itemView.findViewById<ConstraintLayout>(R.id.con_layout_item)
            ivIcon = itemView.findViewById<ImageView>(R.id.img_item)
            tvTitle = itemView.findViewById<TextView>(R.id.tv_title)
        }
    }


    interface onItemClickListener {
        fun onItemCallBack(position: Int)
    }
}